package wh.ispct

import javax.swing.JTable.ModelChange;

class HomeController {

    def index() {
		Content top = Content.findByTop(1)
		def newsM = Menu.findByName("支队新闻")
		List<Content> newsList  = Content.findAll(
			"from Content as c where c.menu = ? order by c.id desc",
			[newsM],[max:9])
		
		def notifyM = Menu.findByName("公告栏")
		List<Content> notifyList = Content.findAll(
			"from Content as c where c.menu = ? order by c.id desc"
			,[notifyM],[max:10])
		
		PageConfig pgCfg = PageConfig.findByPage("index")
		//需要返回的model
		def model = ["topContent":top,
			"newsList":newsList,
			"notifyM":notifyM,
			"notifyList":notifyList,
			pgCfg: pgCfg]
		
		//主页新闻内容菜单
		def menus = [
			pgCfg.menu11,pgCfg.menu12,
			pgCfg.menu21,pgCfg.menu22,
			pgCfg.menu31,pgCfg.menu32,
			pgCfg.menu41
		]
		
		def contentMap =[empty:""]
		menus.each { it ->
			def contentList = Content.findAll("from Content as c where c.menu = ? order by c.id desc"
			,[it]
			,[max:6])
			contentMap[it.name]= contentList
		}
		model.contentMap = contentMap
		
		//督察导航
//		Menu m211 = Menu.findByName("市内督察")
//		model.cityInspLinks = LinkContent.findAllByMenu(m211,[max:9,sort:"sort"])
		
		def inspLinksQuery = """
			select link from LinkContent link
			join link.menu m
		   where m.name = ?
			"""
		model.gsNav = LinkContent.findAllByMenu( Menu.findByName("公安部省厅"),[sort:"sort"])
			
		model.qgNav = LinkContent.findAllByMenu( Menu.findByName("全国导航"),[sort:"sort"])
		model.snNav = LinkContent.findAllByMenu( Menu.findByName("省内导航"),[sort:"sort"])
		
		model.sjNav = LinkContent.findAllByMenu( Menu.findByName("市局机关"),[sort:"sort"])
		model.fxjNav = LinkContent.findAllByMenu( Menu.findByName("县分局支队"),[sort:"sort"])
		
		def contentQuery = """
		select content from Content content
		join content.menu m
	   where m.name = ? order by content.id desc
		"""
		
		model.activityMenu = Menu.findByName("支队动态")
		
		//model.activity = Content.executeQuery(contentQuery,["支队动态"],[max:6])
		model.activity=Content.findAllByMenu(model.activityMenu,[max:6,sort:"id",order:"desc"]) 

		model.complainMenu = Menu.findByName("投诉维权")
		
		model.complain = Content.findAllByMenu(model.complainMenu,[max:6,sort:"id",order:"desc"])

		model.appLinks =LinkContent.findAllByMenu( Menu.findByName("应用系统"),[max:12,sort:"sort"])
		
		def menu=Menu.findByName("系统弹窗")
		model. notices = Content.findAllByMenu( menu,[max:2])
		return model
	 }
	
	def pop(){
		Content c = Content.get(params.id)
		return [content:c]
	}
}
